#ifndef _PHYSICSLAYER_H_
#define _PHYSICSLAYER_H_

#include <SECore/Layer.h>
#include <SECore/Ecs/Component.h>
#include <vector>
#include <unordered_map>
#include <SECore/Signal.h>

class btDefaultCollisionConfiguration;
class btCollisionDispatcher;
class btSequentialImpulseConstraintSolver ;
struct btDbvtBroadphase;
class btDiscreteDynamicsWorld;

namespace SEngine
{

    class RigidBodyPayload;
    class PhysicsLayer : public Layer
    {
    public:
        PhysicsLayer(CoreApplication & app);
        virtual ~PhysicsLayer();
        virtual std::string Name() override { return "PhysicsLayer"; };
        virtual void Attach();
        virtual void Detach() {}
        virtual void BeginFrame() {}
        virtual void EndFrame() {}
        virtual void Update(int delta) override;
        virtual void OnEvent(EventPtr) {}

        void SlotAddComponent(IComponent&);
        void SlotRemoveComponent(IComponent&);

    private:
        btDefaultCollisionConfiguration *               m_btConfig;
        btCollisionDispatcher *                         m_btDispatcher;
        btSequentialImpulseConstraintSolver *           m_btSolver;
        btDbvtBroadphase *                              m_btBroadphase;
        btDiscreteDynamicsWorld *                       m_btWorld;
        std::unordered_map<void*, RigidBodyPayload*>    m_bodies; 
    };   
} // namespace SEngine


#endif